import request from '@/utils/request'
import { parseStrEmpty } from '@/utils/ruoyi'

//获取用户列表
/**request 的 url,method,params是怎么来的？
 *  todo 
 * */
export function getUsers(param) {
  return request({
    url: '/system/user/list',
    method: 'get',
    params: param
  })
}

export function getRoles(param) {
  return request({
    url: '/system/role/list',
    method: 'get',
    params: param
  })
}
//查询部门下拉树结构
export function deptTreeSelect() {
  return request({
    url: '/system/user/deptTree',
    method: 'get'
  })
}
/**PUT请求，json传参*/
export function changeUserStatus(userId, status) {
  const data = { userId, status }
  return request({
    url: '/system/user/changeStatus',
    method: 'put',
    data: data
  })
}

/**岗位列表*/
export function getPosts(param) {
  return request({
    url: '/system/post/list',
    method: 'get',
    params: param
  })
}
// 新增用户
export function addUser(form) {
  return request({
    url: '/system/user',
    method: 'post',
    data: form
  })
}
//用户详情
export function getUserById(userId) {
  return request({
    url: '/system/user/' + parseStrEmpty(userId),
    method: 'get',
  })
}

export function updateUser(data) {
  return request({
    url: '/system/user',
    method: 'put',
    data: data
  })
}

//导入用户
export function importData(data) {
  return request({
    url: '/system/user/importData',
    method: 'post',
    data: data
  })
}
//删除用户
export function deleteUser(userId) {
  return request({
    url: '/system/user/' + userId,
    method: 'delete'
  })
}

export function resetUserPwd(userId, password) {
  const data = { userId, password }
  return request({
    url: '/system/user/resetPwd',
    method: 'put',
    data: data
  })
}